<!--
 * Copyright ©
 * #  
 * @author: zw
 * @date: 2023-02-22 
 -->


<template>
  <div class="icon-body">
    <el-input v-model="name" style="position: relative;" clearable placeholder="请输入图标名称" @clear="filterIcons" @input.native="filterIcons">
      <i slot="suffix" class="el-icon-search el-input__icon" />
    </el-input>
    <div class="icon-list">
      <div v-for="item, index in iconList" :key="index" @click="selectedIcon(item)">
        <i class="iconfont" style="height: 30px;width: 16px;">{{ getIcon(item.label) }}</i>
        <span>{{ item.label }}</span>
      </div>
    </div>
  </div>
</template>

<script>

import { iconList, getIcon } from "@/utils";

export default {
  name: 'IconSelect',
  data() {
    return {
      name: '',
      getIcon,
      iconList,
    }
  },
  methods: {
    filterIcons() {
      if (this.name) {
        this.iconList = this.iconList.filter(item => item.includes(this.name))
      } else {
        this.iconList = iconList
      }
    },
    selectedIcon(name) {
      this.$emit('selected', name)
      document.body.click()
    },
    reset() {
      this.name = ''
      this.iconList = iconList
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.icon-body {
  width: 100%;
  padding: 10px;
  .icon-list {
    height: 200px;
    overflow-y: scroll;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-gap: 10px;
    align-items: center;
    justify-items: center;
    div {
      padding: 2px 4px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      &:hover {
        color: #409eff;
        background-color: #f5f7fa;
      }
    }
  }
}
</style>
